package com.zj.apigateway.client;

import com.zj.apigateway.common.User;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @Auther: zj
 * @Date: 2018/11/23 00:42
 * @Description:
 */
@FeignClient(name = "user",fallback = UserClient.ApiGateWayFallback.class)
public interface UserClient {

    @GetMapping("/getUserByUsername")
    User getUserByUsername(@RequestParam(value = "username") String username);

    @GetMapping("/getUsernameFromToken")
    String getUsernameFromToken(@RequestParam(value = "authToken") String authToken);

    //验证token
    @GetMapping("/validateToken")
    boolean validateToken(@RequestParam(value = "authToken") String authToken,
                          @RequestParam(value = "user") User user);

    @Component
    class ApiGateWayFallback implements UserClient {

        @Override
        public User getUserByUsername(String username) {
            return null;
        }

        @Override
        public String getUsernameFromToken(String token) {
            return "服务降级处理！";
        }

        @Override
        public boolean validateToken(String authToken, User user) {
            return false;
        }
    }
}
